package com.dexgdx.game.manager;

import java.util.ArrayList;
import java.util.List;

import com.dexgdx.game.Game;
import com.dexgdx.game.action.ActionPack;
import com.dexgdx.game.action.IAction;
import com.dexgdx.game.actor.AbstractActor;
import com.dexgdx.game.structure.Region;

public class ActionManager {
	
	public static void runNextInQueue(){
		if(Game.actionData.actionPackList.size() > 0){
			List<ActionPack> finishedPacks = new ArrayList<ActionPack>();
			for (ActionPack actionPack : Game.actionData.actionPackList) {
				actionPack.runNextStep();
				if(actionPack.isFinished()){
					finishedPacks.add(actionPack);
				}
			}
			for (ActionPack actionPack : finishedPacks) {
				Game.actionData.actionPackList.remove(actionPack);
			}
		}
	}

	public static void addToQueue(ActionPack actionPack){
		Game.actionData.actionPackList.add(actionPack);
	}

	public static void addToQueue(IAction action){
		Game.actionData.actionPackList.add(new ActionPack(action));
	}
	
	public static void addMovingActorTarget(AbstractActor actor, Region region){
		actor.setMoving(region);
		if(!Game.actionData.targetOwners.contains(actor)){
			Game.actionData.targetOwners.add(actor);
		}
	}
	
	public static void removeMovingActorTarget(AbstractActor actor){
		actor.unSetMoving();
		Game.actionData.targetOwners.remove(actor);
	}
	
}
